<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Sets the time zone</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="datetimeimmutable.settimestamp.html">« DateTimeImmutable::setTimestamp</a></li>
      <li style="float: right;"><a href="datetimeimmutable.sub.html">DateTimeImmutable::sub »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="class.datetimeimmutable.html">DateTimeImmutable</a></li>
    <li>Sets the time zone</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="datetimeimmutable.settimezone" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">DateTimeImmutable::setTimezone</h1>
  <p class="verinfo">(PHP 5 &gt;= 5.5.0, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">DateTimeImmutable::setTimezone</span> &mdash; <span class="dc-title">Sets the time zone</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-datetimeimmutable.settimezone-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><strong>DateTimeImmutable::setTimezone</strong></span>(<span class="methodparam"><span class="type"><a href="class.datetimezone.html" class="type DateTimeZone">DateTimeZone</a></span> <code class="parameter">$timezone</code></span>): <span class="type"><a href="class.datetimeimmutable.html" class="type DateTimeImmutable">DateTimeImmutable</a></span></div>

  <p class="para rdfs-comment">
   Returns a new DateTimeImmutable object with a new timezone set.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-datetimeimmutable.settimezone-parameters">
  <h3 class="title">参数</h3>
  <dl>
   
    <dt>
<code class="parameter">timezone</code></dt>

    <dd>

     <p class="para">
      A <span class="classname"><a href="class.datetimezone.html" class="classname">DateTimeZone</a></span> object representing the
      desired time zone.
     </p>
    </dd>

   
  </dl>

 </div>


 <div class="refsect1 returnvalues" id="refsect1-datetimeimmutable.settimezone-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   Returns a new modified <span class="classname"><a href="class.datetimeimmutable.html" class="classname">DateTimeImmutable</a></span> object for
   method chaining. The underlaying point-in-time is not changed when calling
   this method.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-datetimeimmutable.settimezone-examples">
  <h3 class="title">范例</h3>
  <div class="example" id="example-2028">
   <p><strong>示例 #1 <span class="function"><strong>DateTimeImmutable::setTimeZone()</strong></span> example</strong></p>
   <div class="example-contents"><p>面向对象风格</p></div>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$date&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">DateTimeImmutable</span><span style="color: #007700">(</span><span style="color: #DD0000">'2000-01-01'</span><span style="color: #007700">,&nbsp;new&nbsp;</span><span style="color: #0000BB">DateTimeZone</span><span style="color: #007700">(</span><span style="color: #DD0000">'Pacific/Nauru'</span><span style="color: #007700">));<br />echo&nbsp;</span><span style="color: #0000BB">$date</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">format</span><span style="color: #007700">(</span><span style="color: #DD0000">'Y-m-d&nbsp;H:i:sP'</span><span style="color: #007700">)&nbsp;.&nbsp;</span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">$newDate&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$date</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">setTimezone</span><span style="color: #007700">(new&nbsp;</span><span style="color: #0000BB">DateTimeZone</span><span style="color: #007700">(</span><span style="color: #DD0000">'Pacific/Chatham'</span><span style="color: #007700">));<br />echo&nbsp;</span><span style="color: #0000BB">$newDate</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">format</span><span style="color: #007700">(</span><span style="color: #DD0000">'Y-m-d&nbsp;H:i:sP'</span><span style="color: #007700">)&nbsp;.&nbsp;</span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
   </div>

   <div class="example-contents"><p>以上例程会输出：</p></div>
   <div class="example-contents screen">
<div class="cdata"><pre>
2000-01-01 00:00:00+12:00
2000-01-01 01:45:00+13:45
</pre></div>
   </div>
  </div>
 </div>


 <div class="refsect1 seealso" id="refsect1-datetimeimmutable.settimezone-seealso">
  <h3 class="title">参见</h3>
  <ul class="simplelist">
   <li class="member"><span class="function"><a href="datetime.gettimezone.html" class="function" rel="rdfs-seeAlso">DateTimeImmutable::getTimezone()</a> - Return time zone relative to given DateTime</span></li>
   <li class="member"><span class="function"><a href="datetimezone.construct.html" class="function" rel="rdfs-seeAlso">DateTimeZone::__construct()</a> - 创建新的DateTimeZone对象</span></li>
  </ul>
 </div>



</div></div></div></body></html>